<?php

namespace App\Http\Middleware;

use App\Exceptions\BusinessException;
use App\Services\Acc;
use App\Services\ResponseCode;
use Closure;

class ApiTokenVerify
{
    /**
     * Handle an incoming request.
     * @param $request
     * @param Closure $next
     * @return mixed
     * @throws BusinessException
     */
    public function handle($request, Closure $next)
    {
        if (false === (new Acc())->isLogin($request->header('Token'))) {
            throw new BusinessException('Unauthorized', ResponseCode::UNAUTHORIZED);
        }

        return $next($request);
    }
}
